﻿using System.ComponentModel;
using FireStarter.Base;
using FireStarter.CodeGeneration.Generator;
using FireStarter.CodeGeneration.Parser;
using FireStarterModeller.BO;
using Habanero.Base;
using Habanero.BO.ClassDefinition;
using Habanero.BO.Loaders;

namespace FireStarterModeller.Logic
{
    public class DmToClassDefsConverter 
    {
        public ClassDefCol Convert(DMSolution solution)
        {
            DMToClassDefsXmlConverter toClassDefsXmlConverter = new DMToClassDefsXmlConverter();
            string xmlForSolution = toClassDefsXmlConverter.ConvertToXml(solution);
            XmlClassDefsLoader loader = new XmlClassDefsLoader(xmlForSolution, new DtdLoader());
            return loader.LoadClassDefs();
        }

        public IClassDef Convert(DMClass dmClass)
        {
            DMToClassDefsXmlConverter toClassDefsXmlConverter = new DMToClassDefsXmlConverter();
            string xmlForClass = toClassDefsXmlConverter.ConvertToXml(dmClass);
            XmlClassLoader loader = new XmlClassLoader(new DtdLoader(), new DefClassFactory());
            return loader.LoadClass(xmlForClass);
        }


        public IUIDef Convert(UIView view)
        {
            DMToClassDefsXmlConverter toClassDefsXmlConverter = new DMToClassDefsXmlConverter();
            string xmlForView = toClassDefsXmlConverter.ConvertToXml(view);
            XmlUILoader loader = new XmlUILoader(new DtdLoader(), new DefClassFactory());
            return loader.LoadUIDef(xmlForView);
        }
    }
}